package cn.zn.modules.budget.cur.controller;

import cn.zn.framework.common.utils.R;
import cn.zn.framework.common.vo.FinanceValues;
import cn.zn.modules.budget.cur.entity.TBudgetInfoDetailAttach;
import cn.zn.modules.budget.cur.service.TBudgetInfoDetailAttachService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.Map;


/**
 * @author zn
 * @email zhunahao@qq.com
 * @date 2019-12-10 14:27:52
 */
@RestController
@RequestMapping("budget/tbudgetinfodetailattach")
public class TBudgetInfoDetailAttachController {

    @Autowired
    private TBudgetInfoDetailAttachService tBudgetInfoDetailAttachService;
    @Autowired
    private FinanceValues financeValues;

    @GetMapping("list/{detailId}")
    public R list(@PathVariable String detailId) {
        return R.ok()
                .put("domain", financeValues.getFile().getDomain())
                .put("list", tBudgetInfoDetailAttachService.list(new QueryWrapper<TBudgetInfoDetailAttach>()
                        .eq("T_BUDGET_INFO_DETAIL_ID_", detailId)
                        .orderByDesc("CREATE_TIME_")
                ));
    }

    @PostMapping("upload/{detailId}")
    public R uploadAttach(@PathVariable String detailId, @RequestParam("fileupload") MultipartFile[] fileupload) {
        tBudgetInfoDetailAttachService.saveAttach(detailId, fileupload);
        return R.ok();
    }

    @DeleteMapping
    public R delete(@RequestBody String[] ids) {
        tBudgetInfoDetailAttachService.deleteAttach(Arrays.asList(ids));
        return R.ok();
    }

}
